import Vue from 'vue'
import VueRouter from 'vue-router'
import layout from '@/views/system/layout'
import flowable from '@/views/flowable/layout'
import os from '@/views/os/layout'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        component: () => import('../views/system/login'),
        meta: {auth: false}
    }, {
        path: '/home',
        component: () => import('../views/system/home'),
        meta: {auth: false}
    }, {
        path: '/index',
        name: 'layout',
        component: layout,
        children: [
            {
                path: 'bpmnModel',
                name: '首页',
                meta: {auth: true},
                component: () => import('../views/flowable/bpmnModel.vue')
            },
            {
                path: 'user',
                name: '用户管理',
                meta: {auth: true},
                component: () => import('../views/system/user.vue')
            },
            {
                path: 'role',
                name: '角色管理',
                meta: {auth: true},
                component: () => import('../views/system/role.vue')
            },
            {
                path: 'resources',
                name: '资源管理',
                meta: {auth: true},
                component: () => import('../views/system/resources.vue')
            },
            {
                path: 'mechanism',
                name: '机构管理',
                meta: {auth: true},
                component: () => import('../views/system/mechanism.vue')
            },
            {
                path: 'dic',
                name: '数据字典',
                meta: {auth: true},
                component: () => import('../views/system/dic.vue')
            },
            {
                path: 'client',
                name: '客户端管理',
                meta: {auth: true},
                component: () => import('../views/system/client.vue')
            }
        ]
    }, {
        path: '/flow',
        name: 'flow',
        component: flowable,
        children: [
            {
                path: 'bpmnModel',
                name: '模型管理',
                meta: {auth: true},
                component: () => import('../views/flowable/bpmnModel.vue')
            }, {
                path: 'processDefinition',
                name: '模型管理',
                meta: {auth: true},
                component: () => import('../views/flowable/processDefinition.vue')
            }, {
                path: 'task',
                name: '任务',
                meta: {auth: true},
                component: () => import('../views/flowable/task.vue')
            }, {
                path: 'processInstance',
                name: '实例',
                meta: {auth: true},
                component: () => import('../views/flowable/processInstance.vue')
            }, {
                path: 'processInstanceHistory',
                name: '历史',
                meta: {auth: true},
                component: () => import('../views/flowable/processInstanceHistory.vue')
            }, {
                path: 'formList',
                name: '表单管理',
                meta: {auth: true},
                component: () => import('../views/flowable/formList.vue')
            }
        ]
    }, {
        path: '/os',
        name: 'os',
        component: os,
        children: [
            {
                path: 'minio',
                name: '静态存储',
                meta: {auth: true},
                component: () => import('../views/os/minio.vue')
            }
        ]
    }
]

const router = new VueRouter({
    routes
})

router.beforeEach((to, from, next) => {
    console.log('开始页面切换');
    console.log(to.fullPath)
    let userInfo = sessionStorage.getItem('access_token');
    if(to.fullPath !== '/' && ( userInfo == null || userInfo === '')){
        window.location.href = '/';
    }
    next();
});
export default router
